package com.altersoftware.hotel.dao;

import com.altersoftware.hotel.entity.CustomerDO;
import org.apache.ibatis.annotations.*;

/**
 * @author czy@win10
 * @date 2020/1/22 14:28
 */
@Mapper
public interface CustomerDAO {

    /**
     * 插入一个客户
     * t
     *
     * @param customerDO
     */
    @Insert(" INSERT INTO tb_customer (customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time ) "
            +
            "VALUES(#{id}, #{name}, #{idCard}, #{sex}, #{age}, #{mobile}, #{account}, #{password}, #{faceId}, #{email}, NOW(), NOW()) ")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "customer_number")
    void insert(CustomerDO customerDO);

    /**
     * 通过id查找客户
     * 
     * @param id
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_number=#{id} ")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOById(@Param("id") long id);

    /**
     * 通过手机查询客户
     *
     * @param mobile
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_tel=#{mobile} ")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOByMobile(@Param("mobile")String mobile);

    /**
     * 通过邮箱查询客户
     *
     * @param email
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_mail=#{email} ")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOByEmail(@Param("email")String email);

    /**
     * 通过邮箱和密码验证用户
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_mail=#{email} and customer_password=#{password} ")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOByEmailAndPassword(@Param("email")String email,@Param("password")String password);

    /**
     * 通过手机和密码验证用户
     *
     * @param  mobile
     * @param  password
     * @return
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_tel=#{mobile} and customer_password=#{password}")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOByMobileAndPassword(@Param("mobile")String mobile,@Param("password")String password);

    /**
     * 更新客户
     *
     * @return
     */
    @Update("update tb_customer  set customer_name=#{name}, customer_id=#{idCard}, customer_sex=#{sex}, customer_age=#{age}, customer_tel=#{mobile}, customer_account=#{account}, customer_password=#{password}, customer_faceid=#{faceId}, customer_mail=#{email}, modify_time=now()"
            +
            "where customer_number=#{id}")
    int update(CustomerDO staffDO);

    /**
     * 删除客户
     *
     * @param id
     */
    @Delete("DELETE FROM tb_customer WHERE customer_number=#{id}")
    void deleteById(long id);

    /**
     * 通过faceId查找用户
     *
     * @param faceId
     */
    @Select(" select customer_number, customer_name, customer_id, customer_sex, customer_age, customer_tel, customer_account, customer_password, customer_faceid, customer_mail, create_time, modify_time"
            +
            " from tb_customer where customer_faceid=#{faceId} ")
    @Results({
            @Result(property = "id", column = "customer_number"),
            @Result(property = "name", column = "customer_name"),
            @Result(property = "idCard", column = "customer_id"),
            @Result(property = "sex", column = "customer_sex"),
            @Result(property = "age", column = "customer_age"),
            @Result(property = "mobile", column = "customer_tel"),
            @Result(property = "account", column = "customer_account"),
            @Result(property = "password", column = "customer_password"),
            @Result(property = "faceId", column = "customer_faceid"),
            @Result(property = "email", column = "customer_mail"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "modifyTime", column = "modify_time")
    })
    CustomerDO getCustomerDOByfaceId(@Param("faceId")String faceId);
}
